#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :schemas.py
# @Time      :2021/6/21 16:11
# @Author    : 刘广鸿

from typing import List, Optional, Dict
from pydantic import BaseModel


# 所有的Base 是读取和创建时的共有属性  Create是创建时的所需要属性

class UserBase(BaseModel):
    username: str

    # password = Column(String, nullable=False)
    # token = Column(String, server_default="NO token", nullable=False)  # 访问凭证
    # Devices = Column(Text, nullable=True)  # 所管理设备列表
    class Config:
        orm_mode = True


class UserCreate(UserBase):
    password: str


class UserDevices(UserBase):
    Devices: list


class DeviceBase(BaseModel):
    type: int
    name: str
    note: str

    # devices_key = Column(String, nullable=False)  # 设备秘钥  uuid + 时间戳  =》MD5 加密
    # uuid = relationship("Datas", back_populates="device")  # Datas -->device
    class Config:
        orm_mode = True


class DeviceCreate(DeviceBase):
    devices_key: str
    uuid: str


class DatasBase(BaseModel):
    dataType: str
    value: str  # 数据值
    id: str  # 标识符
    datetime: str  # 时间
    device: str  # 外键关联 Devices --> uuid

    class Config:
        orm_mode = True


class BindDevice(BaseModel):
    username: str
    token: str
    uuid: str
    device_key: str


class LoginForm(BaseModel):
    username: str
    password: str


class UpdatePasswordForm(BaseModel):
    username: str
    token: str
    oldpassword: str
    newpassword: str
